﻿using IdentityServer4.EntityFramework.DbContexts;
using IdentityServer4.EntityFramework.Options;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Ids4DemoEFServer.Data
{
    public class TemporaryDbContextFactory
    {
        public class TemporaryDbContextFactoryScopes : IDesignTimeDbContextFactory<PersistedGrantDbContext>
        {
            public PersistedGrantDbContext CreateDbContext(string[] args)
            {
                var builder = new DbContextOptionsBuilder<PersistedGrantDbContext>();
                builder.UseSqlServer("data source=(LocalDB)\\MSSQLLocalDB;initial catalog=Ids4EFServer;integrated security=True;",
                    optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(PersistedGrantDbContext).GetTypeInfo().Assembly.GetName().Name));
                return new PersistedGrantDbContext(builder.Options, new OperationalStoreOptions());
            }
        }

        public class TemporaryDbContextFactoryOperational : IDesignTimeDbContextFactory<ConfigurationDbContext>
        {
            public ConfigurationDbContext CreateDbContext(string[] args)
            {
                var builder = new DbContextOptionsBuilder<ConfigurationDbContext>();
                builder.UseSqlServer("data source=(LocalDB)\\MSSQLLocalDB;initial catalog=Ids4EFServer;integrated security=True;",
                    optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(ConfigurationDbContext).GetTypeInfo().Assembly.GetName().Name));

                return new ConfigurationDbContext(builder.Options, new ConfigurationStoreOptions());
            }
        }
    }
}
